package managerSIP;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.ListIterator;
import java.util.Observable;

import net.sf.asterisk.manager.AuthenticationFailedException;
import net.sf.asterisk.manager.TimeoutException;

public class Session extends Observable {

	public void delUserSession (AsteriskSession astSessionsrc, String user){
		astSessionsrc.usersSession.remove(user);
	}

	@SuppressWarnings("unchecked")
	
	public void addUserSession (AsteriskSession astSessiondst, String user){
		astSessiondst.usersSession.add(user);
	}


	public void changeSession (String user, int confSource, Conference conferenceMgr, AsteriskSession astSessionsrc, AsteriskSession astSessiondst) 
	throws IOException, IllegalArgumentException, IllegalStateException, SQLException, AuthenticationFailedException, TimeoutException {
		List userlist = (List)astSessionsrc.conferences.get(confSource);
		for (ListIterator it = userlist.listIterator(); it.hasNext();) {
			String strUserList = it.next().toString();
			if (!strUserList.isEmpty() && user.equals(strUserList)){
				String userconf = (String)astSessionsrc.usersID.get(user);
				conferenceMgr.kickUser(userconf, confSource);
			}
		}
		userlist.remove(user);
		astSessionsrc.usersID.remove(user);
		astSessionsrc.usersConf.remove(user);
		delUserSession(astSessionsrc, user);
		addUserSession(astSessiondst, user);
	}
}
